import com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI;
import com.sun.org.apache.xerces.internal.impl.xs.util.XIntPool;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-05-30
 * Time: 21:44
 * @author 86189
 */
public class Main {
    public static int findPosition(int[] array,int target){
        return binarySearch(array,0,array.length-1,target);
    }
    public static int binarySearch(int[] array,int start,int end,int target){
        int left=start;
        int right=end;
        while ( left <= right ){
            int mid=(left+right)/2;
            if(array[mid]<target){
                left=mid+1;
            }else if(array[mid]> target){
                right=mid-1;
            }else{
                return mid;
            }
        }
        return -1;
    }
    public static void main (String[] args) {
        int[] array={1,3,5,223,546,12,2};
        System.out.println( findPosition( array , 5 ) );
    }
}
